package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.ShelvesgroupEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.ProductcategoryEntity;
import io.renren.modules.sys.service.ProductcategoryService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-03-21 17:08:45
 */
@RestController
@RequestMapping("sys/productcategory")
public class ProductcategoryController {
    @Autowired
    private ProductcategoryService productcategoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:productcategory:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = productcategoryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:productcategory:info")
    public R info(@PathVariable("id") Integer id){
        ProductcategoryEntity productcategory = productcategoryService.getById(id);

        return R.ok().put("productcategory", productcategory);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:productcategory:save")
    public R save(@RequestBody ProductcategoryEntity productcategory){
        productcategoryService.save(productcategory);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:productcategory:update")
    public R update(@RequestBody ProductcategoryEntity productcategory){
        ValidatorUtils.validateEntity(productcategory);
        productcategoryService.updateById(productcategory);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("sys:productcategory:delete")
    public R delete(@PathVariable("id") Integer id){
        productcategoryService.removeById(id);

        return R.ok();
    }


    /**
     * 查询所有商品分类信息
     */
    @RequestMapping("/alllist")
    @RequiresPermissions("sys:productcategory:alllist")
    public R alllist(){
        List<ProductcategoryEntity> alllist = productcategoryService.list(new QueryWrapper<ProductcategoryEntity>());
        return R.ok().put("alllist", alllist);
    }

}
